import java.util.*;


class Person{
    public String id;
    public Person(String id){
        this.id = id;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Person person = (Person) o;
        return Objects.equals(id, person.id);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }
}
public class HashBuck2<K,V> {
    static class Node<K,V>{
        public K key;
        public V val;
        public Node<K,V> next;

        public Node(K key, V val) {
            this.key = key;
            this.val = val;
        }
    }
    public Node<K,V>[] array;
    public int usedSize;
    public HashBuck2(){
        array =(Node<K,V>[])new Node[10];
    }
    public void put(K key,V val){
        //int index = key % array.length; 自定义类型非整数
        //hashCode() 将对象转换为整数
        int hash = key.hashCode();
        int index = hash % array.length;
        Node cur = array[index];
        while(cur != null){
            if(cur.key.equals(key)){
                cur.val = val;//更新val的值
                return;
            }
            cur = cur.next;
        }
        //头插
        Node<K,V> node =new Node<>(key,val);
        node.next = array[index];
        array[index] = node;
        usedSize++;
    }

    public V get(K key){
        int hash = key.hashCode();
        int index = hash % array.length;
        Node<K,V> cur = array[index];
        while(cur != null){
            if(cur.key.equals(key)){
                return cur.val;
            }
            cur = cur.next;
        }
        return null;
    }

    public int singleNumber(int[] nums) {
        Set<Integer> set = new HashSet<>();
        for(int i = 0; i < nums.length;i++){
            if(set.contains(nums[i])){
                set.remove(nums[i]);
            }else{
                set.add(nums[i]);
            }
        }
        for(int i = 0 ;i<nums.length;i++){
            if(set.contains(nums[i])){
                return nums[i];
            }
        }
        return -1;
    }

    //随机链表的复制
   /* public Node copyRandomList(Node head) {
        HashMap<Node,Node> map = new HashMap<>();
        Node cur = head;
        while(cur != null){
            Node node = new Node(cur.val);
            map.put(cur,node);
            cur = cur.next;
        }
        cur = head;
        while(cur != null){
            map.get(cur).next = map.get(cur.next);
            map.get(cur).random = map.get(cur.random);
            cur = cur.next;
        }
        return map.get(head);

    }*/

    //宝石与石头
    public int numJewelsInStones(String jewels, String stones) {
        Set<Character> set = new HashSet<>();

        for(char ch:jewels.toCharArray()){
            set.add(ch);
        }
        int count = 0;
        for(char ch:stones.toCharArray()){
            if (set.contains(ch)){//使用 set.contains(ch) 检查它是否在之前创建的集合中
                count++;
            }
        }
        return count;
    }



}
